import React from 'react';
import ReactDOM from 'react-dom/client';
import { ConfigProvider } from 'antd';
import { Provider } from 'react-redux';
import dayjs from 'dayjs';
import store from './library/redux/store';
import App from './library/app/App';
import i18n from './../.rnext/library/app/i18n';
import enUS from 'antd/lib/locale/en_US';
import zhCN from 'antd/lib/locale/zh_CN';
import 'dayjs/locale/zh-cn';
import reportWebVitals from './reportWebVitals';

if(i18n.language !== 'en') {
  require('dayjs/locale/zh-cn');
  dayjs.locale('zh-cn');
}

const RootApp = () => (
  <Provider store={store}>
    <ConfigProvider locale={i18n.language === 'en' ? enUS : zhCN}>
      <App />
    </ConfigProvider>
  </Provider>
)

const root = ReactDOM.createRoot(
  document.getElementById('root') as HTMLElement
);

i18n.init().then(() => {
  setTimeout(() => {
    root.render(
      <RootApp />
    );
  }, 100)
}).catch(() => {
  root.render(
    <RootApp />
  );
})


// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
